#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
ull a[N], b[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) cin >> b[i];
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  stack<ull> st;
  vector<ull> c;
  ull pre = 0;
  rep(i, 1, n) {
    if (a[i] >= pre + 1) {
      while (st.size() && a[i] > pre + 1) {
        c.push_back(++pre - st.top());
        st.pop();
      }
      pre = a[i];
    } else {
      st.push(a[i]);
    }
  }
  while (st.size()) {
    c.push_back(++pre - st.top());
    st.pop();
  }
  sort(c.begin(), c.end(), greater<ull>());
  m = c.size();
  ull ans = 0;
  rep(i, 1, m) { ans += b[i] * c[i - 1]; }
  cout << ans;
  return 0;
}